package com.leetcode.array;

import java.util.Arrays;
import java.util.PriorityQueue;

public class HalveArray {
    public static void main(String[] args) {
        System.out.println(3.5/2.0);
        System.out.println(7 - 2.5);
    }
    
    public int halveArray(int[] nums) {
        PriorityQueue<Double> queue = new PriorityQueue<>((a, b) -> b.compareTo(a));
        for (int num : nums) {
            queue.offer((double)num);
        }
        double sum = 0.0;
        for (int num : nums) {
            sum += num;
        }
        int res = 0;
        double sum2 = 0.0;
        while (sum2 < sum / 2.0) {
            double max = queue.poll();
            sum2 += max / 2.0;
            res++;
            queue.offer(max / 2.0);
        }
        return res;
    }
}
